package vworld.business.user;

import generated.business.avatar.AvatarServicePackage.Gender;
import generated.business.avatar.AvatarServicePackage.Mood;
import generated.business.avatar.AvatarServicePackage.Size;
import generated.business.user.UserServicePOA;
import generated.domain.avatar.Avatar;
import generated.domain.user.User;

import org.omg.CORBA.ORB;

import vworld.ServerSingleton;

public class UserServiceServant extends UserServicePOA {

	private ORB orb;

	public void setOrb(ORB pOrb) {
		orb = pOrb;
	}

	public User createUser(String pName, String pRole, String pEmail,
			String pLogin, String pPassword) {
		User user = new User();
		user.setName(pName);
		user.setRole(pRole);
		user.setEmail(pEmail);
		user.setLogin(pLogin);
		user.setPassword(pPassword);

		Avatar avatar = new Avatar();
		avatar.setGender(Gender.male.toString());
		avatar.setMood(Mood.happy.toString());
		avatar.setName("");
		avatar.setSize(Size.small.toString());
		user.setAvatar(avatar);

		boolean created = ServerSingleton.getInstance().USER_DAO
				.createUser(user);

		if (created) {
			return user;
		} else {
			// TODO HACK
			if (!user.getRole().equalsIgnoreCase("administrator")) {
				user.setRole("");
			}
			return user;
		}
	}

	public Avatar getAvatar(User pUser) {
		return ServerSingleton.getInstance().USER_DAO.getAvatar(pUser);
	}

	public boolean removeAvatar(User user) {
		return false;
	}

	public User getUserByLogin(String userLogin) {
		return ServerSingleton.getInstance().USER_DAO.getUser(userLogin);
	}
}
